package com.tomhu.util;

import javax.swing.JOptionPane;


/**
 * 比较符号的优先级！！
 * @author tomhu
 *
 */
public class ComparePriority {

	public static boolean isHighPriority(String operate1, String operate2) {

		boolean flag = false;
		if (compareOperate(operate1, operate2) > 0) {
			flag = true;
		}
		return flag;
	}

	public static boolean isEqualPriority(String operate1, String operate2) {

		boolean flag = false;
		if (compareOperate(operate1, operate2) == 0) {
			flag = true;
		}

		return flag;
	}

	public static boolean isLowPriority(String operate1, String operate2) {
		
		return isHighPriority(operate2, operate1);
	}

	// 将运算符的优先级用数学间接表示！！
	public static int convertIntoNumber(String operate) {

		int priority = -1;
		if (operate.equals("+") || operate.equals("-")) {
			priority = 0;
		} else if (operate.equals("*") || operate.equals("/")) {
			priority = 1;
		} else {
			JOptionPane.showMessageDialog(null, "错误的运算符！");
		}
		return priority;
	}

	public static int compareOperate(String operate1, String operate2) {

		int operateNumber1 = convertIntoNumber(operate1);
		int operateNumber2 = convertIntoNumber(operate2);

		return operateNumber1 - operateNumber2;
	}
}
